<?php
/**
 * Object Relational Persistence Mapping Class for table: lab_group
 * @package modules.dept_laboratory.ordo
 * @author viethd
 * @version $Id$
 * @copyright 2009 LHV Company
 */
class LabGroup extends ORDataObject {

    /**#@+
     * Fields of table: lab_group mapped to class members
     */
    var $lab_group_id		= '';
    var $vi_name		= '';
    var $en_name		= '';
    /**#@-*/


    /**
     * DB Table
     */
    var $_table = 'lab_group';

    /**
     * Primary Key
     */
    var $_key = 'lab_group_id';

    /**
     * Internal Name
     */
    var $_internalName = 'LabGroup';

    /**
     * Handle instantiation
     */
    function __construct() {
        parent::ORDataObject();
    }

    public function loadLabGroups() {
        $field    =   L10nHelper::changeField(L10nHelper::getLocale(), 'name');
        $ds =& new Datasource_sql();
        $sql = array(
            'cols'  => "t.lab_group_id, t.$field name",
            'from'  => "$this->_table t",            
            'orderby' => "t.lab_group_id"
        );
        $ds->setup($this->_db, $sql);
        return $ds->toArray();
    }

    public function addLabGroup($text) {
        $langs = L10nHelper::getSupportedLocales();
        foreach ($langs as $lo){
        	 $field    =   L10nHelper::changeField($lo, 'name');
        	 $data[$field] = $text;
        }
        $this->populateArray($data);
        $this->persist();
        return $this->get_id();
    }

    public function updateLabGroup($labGroupId, $text) {
    	$field    =   L10nHelper::changeField(L10nHelper::getLocale(), 'name');
        $this->setup($labGroupId);
        if ($this->get_id() == 0) {
           	$this->addLabGroup($text);
        } else {
        	$data[$field] = $text;
            $this->populateArray($data);
        	$this->persist();
        }
        return $this->get_id();
    }

    // TODO localization ptnguyen 2010-03-17
    // Empty function
    public function checkDuplicateName($nameText, $groupId, $forAddnew = true) {
        
    }



}
?>
